package es.uned.hoomgle.hibernate.beans.impl;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import es.uned.hoomgle.hibernate.beans.interfaces.RoleI;

@Entity
public class Role implements RoleI {

	@Id
	@Column
	@GeneratedValue
	private Long id;
	
	@Column
	private String name;
	
	@ManyToMany(cascade = CascadeType.ALL) 
	@JoinTable(name="USER_ROLE",joinColumns=@JoinColumn(name="id_role"),
	inverseJoinColumns=@JoinColumn(name="id_user"))	
	public List<User> users;
	
	
	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.RoleI#getId()
	 */
	@Override
	public Long getId() {
		return id;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.RoleI#setId(java.lang.Long)
	 */
	@Override
	public void setId(Long id) {
		this.id = id;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.RoleI#getName()
	 */
	@Override
	public String getName() {
		return name;
	}

	/* (non-Javadoc)
	 * @see es.uned.hoomgle.hibernate.beans.impl.RoleI#setName(java.lang.String)
	 */
	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Role [id=");
		builder.append(id);
		builder.append(", name=");
		builder.append(name);
		builder.append("]");
		return builder.toString();
	}
	
	
	
}
